﻿Shader "Unlit/AfterShader"
{
   Properties
    {
        _Color ("Color",Color) = (0,0,0,1)
        _MainTex ("MainTex", 2d) = "white"{}
        _Direction ("Direction", vector) = (0,0,0,1)
    }
    SubShader
    {       
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            sampler2D _MainTex;
            half4 _Direction;
            float4 _MainTex_ST;
            float4 _Color;

            struct appdata
            {
                float4 position : POSITION;
                float2 uv : TEXCOORD0;
                half3 normal:NORMAL;
            };

            struct v2f
            {
                float4 position : SV_POSITION;
                float2 uv:TEXCOORD0;
            };

            v2f vert (appdata v)
            {
                v2f o;   
                //噪波算法
                float noise = frac(sin(dot(v.uv.xy, float2(12.9898, 78.233))) * 43758.5453);
                //变换拉伸
                fixed NdotD = max(0,dot(_Direction,v.normal));
                v.position.xyz += _Direction.xyz * _Direction.w * noise * NdotD;
                o.position = UnityObjectToClipPos(v.position);
                o.uv = TRANSFORM_TEX(v.uv,_MainTex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            { 
                fixed4 col = tex2D(_MainTex,i.uv);
                col+=_Color;
                return col;
            }
            ENDCG
        }
    }
}
